<?php
namespace app\admin\model\logic;

use think\Model;

class AdminLog extends Model{
     //设置模型链接的表名
    protected $name = 'admin_log';
    protected $log;
    //逻辑层user模型初始化存储层方法
    public function __construct()
    {
        $this->log = app('app\admin\model\db\AdminLog');
    }
    //记录后台系统日志
    public function record_log()
    {
        $in_data['id'] =$this->log->count()+1;
        $in_data['admin_id'] = cookie("adminid");
        $request =request();
        $in_data['controller'] =  $request->controller();
        $in_data['action'] = $request->action();
        $post_data=json_encode(input(),JSON_UNESCAPED_UNICODE);
        if(strlen($post_data)>500){
            $in_data['act_data'] =mb_substr($post_data,0,500,"UTF-8");
        }else{
            $in_data['act_data'] =$post_data;
        }
        $in_data['act_ip'] = request()->ip();
        $in_data['act_time'] = time();
        $in_data['act_time_str'] = date("Y-m-d H:i:s");
        // $this->log->allowField(true)->isUpdate(false)->save($in_data); // tp6已废除allowfield传递bool类型，isupdate方法废除
        $this->log->replace()->save($in_data);
    }
}